﻿using System;
using System.Reflection;
public class Person
{
    public string Name { get; set; }
    public int Age { get; set; }

    public Person()
    {
        Name = "Unknown";
        Age = 0;
    }

    public Person(string name, int age)
    {
        Name = name;
        Age = age;
    }

    public void Display()
    {
        Console.WriteLine($"Name: {Name}, Age: {Age}");
    }
}

class Program
{
    static void Main(string[] args)
    {
        // 获取Person类的Type对象
        Type personType = typeof(Person);

        // 使用无参数的构造函数创建实例
        Person person1 = (Person)Activator.CreateInstance(personType);
        person1.Display();

        // 获取有参数的构造函数
        ConstructorInfo ctor = personType.GetConstructor(new[] { typeof(string), typeof(int) });
        // 使用有参数的构造函数创建实例
        if (ctor != null)
        {
            Person person2 = (Person)ctor.Invoke(new object[] { "John Doe", 30 });
            person2.Display();
        }
    }
}
